from flask import Blueprint, jsonify
from .house_controller import HouseController
from .review_controller import ReviewController

bp = Blueprint('routes', __name__)

@bp.route('/ping')
def ping():
    return jsonify({"msg": "pong"})

@bp.route('/login')
def login():
    return jsonify({"msg": "login"})

# 房屋管理路由
@bp.route('/houses', methods=['POST'])
def create_house():
    """创建房源"""
    return HouseController.create_house()

@bp.route('/houses/<int:houseid>', methods=['DELETE'])
def delete_house(houseid):
    """删除房源"""
    return HouseController.delete_house(houseid)


@bp.route('/houses/<int:houseid>', methods=['GET'])
def get_house(houseid):
    """获取单个房源详情（包含评价）"""
    return HouseController.get_house(houseid)

@bp.route('/houses/search', methods=['GET'])
def search_houses():
    """搜索房源"""
    return HouseController.search_houses()

@bp.route('/houses/<int:houseid>', methods=['PUT'])
def update_house(houseid):
    """统一更新房源信息（基础信息、地址、设施）"""
    return HouseController.update_house_unified(houseid)

@bp.route('/houses/user', methods=['GET'])
def get_user_houses():
    """获取当前用户的房源（按状态分类）"""
    return HouseController.get_user_houses()

@bp.route('/houses', methods=['GET'])
def get_all_houses():
    """获取所有房源列表（分页）"""
    return HouseController.get_all_houses()




# 评价管理路由
@bp.route('/reviews', methods=['POST'])
def create_review():
    """创建评价"""
    return ReviewController.create_review()

@bp.route('/reviews/<int:reviewid>', methods=['GET'])
def get_review(reviewid):
    """获取单个评价详情"""
    return ReviewController.get_review(reviewid)

@bp.route('/houses/<int:houseid>/reviews', methods=['GET'])
def get_house_reviews(houseid):
    """获取房源的所有评价"""
    return ReviewController.get_house_reviews(houseid)

@bp.route('/reviews/user', methods=['GET'])
def get_user_reviews():
    """获取当前用户的所有评价"""
    return ReviewController.get_user_reviews()

@bp.route('/reviews/<int:reviewid>', methods=['PUT'])
def update_review(reviewid):
    """更新评价"""
    return ReviewController.update_review(reviewid)

@bp.route('/reviews/<int:reviewid>', methods=['DELETE'])
def delete_review(reviewid):
    """删除评价"""
    return ReviewController.delete_review(reviewid)